﻿package mortal.game.view.closedBetaGiftBagNew.panel
{
    import __AS3__.vec.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import fl.data.*;
    import flash.geom.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.resource.*;
    import mortal.game.view.closedBetaGiftBagNew.cellRender.*;
    import mortal.game.view.closedBetaGiftBagNew.group.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;

    public class ClosedBetaLevelGiftView extends ClosedBetaBasePanel
    {
        private var _giftList:GTileList;
        private var _selectedGiftIndex:int;

        public function ClosedBetaLevelGiftView()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildren();
            pushUIToDisposeVec(UIFactory.bg(5, 138, 892, 417, this, ImagesConst.PanelBg));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.closedBetaGiftBagNewBg, 5, 30, this));
            this._giftList = UIFactory.tileList(18, 146, 890, 400, this);
            this._giftList.setStyle("cellRenderer", ClosedbetaLevelGiftCellRender);
            this._giftList.columnWidth = 164 + 8;
            this._giftList.rowHeight = 198 + 5;
            this._giftList.direction = GBoxDirection.VERTICAL;
            this._giftList.dataProvider = this.getLevelGiftDataProvider();
            this._giftList.drawNow();
            this._giftList.scrollToIndex(this._selectedGiftIndex);
            return;
        }// end function

        private function getLevelGiftDataProvider() : DataProvider
        {
            var _loc_1:* = new DataProvider();
            var _loc_2:* = Cache.instance.closedBetaLevelGift.levelGiftVec;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2.length)
            {
                
                _loc_1.addItem(_loc_2[_loc_3]);
                if (this._selectedGiftIndex <= 0)
                {
                    if (_loc_2[_loc_3].receiveType == ClosedBetaBaseGroup.CanReceive)
                    {
                        this._selectedGiftIndex = _loc_3;
                    }
                }
                _loc_3++;
            }
            return _loc_1;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._giftList.dispose(param1);
            this._giftList = null;
            return;
        }// end function

        private function onClosedBetaGiftBagFlyToPack(event:DataEvent) : void
        {
            if (isDisposed)
            {
                return;
            }
            var _loc_2:* = event.data as int;
            if (_loc_2 != 0)
            {
                return;
            }
            var _loc_3:* = new Point(663, 164);
            FlyToNavbarTool.flyToBackPack(GlobalClass.getBitmapData(ImagesConst.ClosedBetaGiftBagItem), _loc_3);
            return;
        }// end function

        override public function refresh() : void
        {
            this._selectedGiftIndex = -1;
            this._giftList.dataProvider = this.getLevelGiftDataProvider();
            this._giftList.drawNow();
            this._giftList.scrollToIndex(this._selectedGiftIndex);
            return;
        }// end function

    }
}
